package cn.gary.oaserver.config.utils;

import cn.gary.oaserver.entity.TAdmin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;

/**
 * @Author: 邓必宏
 * @title:
 * @Demo:
 * @DateTime: 2024/4/10
 */
@Component
public class RedisUtil {

    @Autowired
     RedisTemplate<String, Object> redisTemplate;

    public void clearMenuListFromRedis() {
        // 1、得到当前登录用户的ID
        Integer adminId = ((TAdmin) (SecurityContextHolder.getContext ( ).getAuthentication ( ).getPrincipal ( ))).getId ( );
        // 2、从redis中清空之前缓存的菜单列表数据
        System.out.println ( redisTemplate );
        System.out.println ( redisTemplate.opsForValue ( ) );
        redisTemplate.delete ( "menu_" + adminId );
        if (redisTemplate.opsForValue ( ).get ( ConstansOA.REDIS_MENU ) != null) {
            redisTemplate.delete ( ConstansOA.REDIS_MENU );
        }
    }
}
